<html>
<head>
<title>ASP.NET Validation Controls</title>
<script language="javascript" 
        src="/js/WebUIValidation.js">
</script>
<script language="JScript">
<!--
// client-side validation function for CustomValidator
function ClientValidate(objSource, strValue) {
  var blnValid = true;
  var intNumber = strValue;
  if (intNumber % 2 == 1) {
    var intDivisor = Math.floor(intNumber / 3);
    if (intDivisor > 2) {
      for (var i = 3; i <= intDivisor; i = i + 2) {
        if (intNumber % intDivisor == 0) {
          blnValid = false;
          break;
        }
      }
    }
    else
      blnValid = false;
  }
  else
    blnValid = false;
  return blnValid;
}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<!--------------------------------------------------------------------------->
<span class="heading">CustomValidator</span> &nbsp; &nbsp; &nbsp;
<form runat="server" action="getvalue.aspx" method="post">
 <table border="0">

<tr>
  <td valign="top">Number over 100</td>
  <td><input type="text" id="txtNumber" 
	maxlength="50" size="20" runat="server" />
	<asp:RequiredFieldValidator id="valRequired" runat="server"
          	 ControlToValidate="txtNumber"
          	 ErrorMessage="* You must enter a valid number over 100 (Require)"
          	 Display="dynamic">
          	 *
      </asp:RequiredFieldValidator><br />
      <asp:CompareValidator 
	id="valCompare" runat="server"             
	ControlToValidate="txtNumber"
	 ValueToCompare="100"
              Operator="GreaterThan"
	Type="Integer"
              ErrorMessage="* You must enter a valid number over 100 (Compare)"
               Display="dynamic">
             *
      </asp:CompareValidator> <br />
     <asp:CustomValidator id="valClientScript" runat="server"
           	ControlToValidate="txtNumber"      
	ClientValidationFunction="ClientValidate"        	       
	ErrorMessage="* You must enter valid number over 100 (Custom)"
           	Display="dynamic">
           	Please enter valid number over 100.
      </asp:CustomValidator>
  </td>
 </tr>
 </table>

<asp:ValidationSummary id="valSummary" runat="server"
     HeaderText="<b>The following errors were found:</b>"
     ShowSummary="true" DisplayMode="List" />

<hr />

<input type="submit" id="cmdConfirm" value="Submit"  runat="server">&nbsp; &nbsp;
<input type="submit" id="cmdCancel" value="Cancel" runat="server" onserverclick="CancelEntry">&nbsp; &nbsp;
</form>
<div id="outMessage" EnableViewState="False" runat="server" />

<script language="VB" runat="server">
Sub Page_Load()
  Dim objValidator As BaseValidator
  For Each objValidator In Page.Validators
    objValidator.Enabled =True
    objValidator.EnableClientScript=True
  Next
  valSummary.ShowMessageBox = True
End Sub



Sub ConfirmEntry(objSender As Object, objArgs As EventArgs)
  outMessage.InnerHtml = "Page.IsValid returned <b>" & Page.IsValid & ".</b>"
End Sub

Sub CancelEntry(objSender As Object, objArgs As EventArgs)
  outMessage.InnerHtml = "Validation was not carried out."
End Sub
</script>
</body>
</html>

